package com.zhongke.home.ui.activity

import android.graphics.Color
import android.os.Bundle
import android.view.View
import androidx.fragment.app.Fragment
import com.alibaba.android.arouter.launcher.ARouter
import com.next.easynavigation.view.EasyNavigationBar
import com.zhongke.common.base.activity.ZKBaseActivity
import com.zhongke.common.router.ZKRouterFragmentPath
import com.zhongke.home.BR
import com.zhongke.home.R
import com.zhongke.home.databinding.ActivityTabHomeBinding
import com.zhongke.home.ui.fragment.ChooseFragment
import com.zhongke.home.ui.fragment.HomeFragment
import com.zhongke.home.ui.fragment.ShopCarFragment
import com.zhongke.home.ui.viewmodel.ZKHomeViewModel

/**
 * @author: hyb4600
 * @date: 2022/5/10
 * @description：底部导航栏使用的是第三方EasyNavigation框架
 * 更多方法设置请查阅框架github 使用教程
 * 框架地址：https://github.com/Vincent7Wong/EasyNavigation
 */
class ZKTabActivity : ZKBaseActivity<ActivityTabHomeBinding, ZKHomeViewModel>() {

    private val fragments = ArrayList<Fragment>()

    /**
     * 底部导航栏的名称
     * 到时候直接替换数组名字就好
     */
    private var strings = arrayOf("首页", "分类", "购物车", "会员中心")

    /**
     * 底部导航栏未选中时候的图标
     * 到时候直接替换数组图片就好
     */
    private var unSelectList = intArrayOf(R.mipmap.ic_launcher,
        R.mipmap.ic_launcher,
        R.mipmap.ic_launcher,
        R.mipmap.ic_launcher)
    /**
     * 底部导航栏选中时候的图标
     *  到时候直接替换数组图片就好
     */
    private var selectList = intArrayOf(R.mipmap.ic_launcher,
        R.mipmap.ic_launcher,
        R.mipmap.ic_launcher,
        R.mipmap.ic_launcher)
    private var easyBars: EasyNavigationBar? = null
    override fun initContentView(savedInstanceState: Bundle?): Int {
        return R.layout.activity_tab_home
    }

    override fun initVariableId(): Int {
        return BR.viewModel
    }

    override fun initData() {
        easyBars = binding.easyBars
        fragments.add(HomeFragment())
        fragments.add(ChooseFragment())
        fragments.add(ShopCarFragment())
        var myFragment= ARouter.getInstance().build(ZKRouterFragmentPath.Mine.PAGER_MY).navigation() as Fragment
        fragments.add(myFragment)
        easyBars?.titleItems(strings)
        easyBars?.fragmentList(fragments)//存放fragment的集合
        easyBars?.fragmentManager(supportFragmentManager)//fragment管理器
        easyBars?.selectIconItems(selectList)//选中的图片
        easyBars?.normalIconItems(unSelectList)//未选中的图片
        easyBars?.canScroll(true)//可以滑动
        easyBars?.mode(EasyNavigationBar.NavigationMode.MODE_NORMAL)
        /**
         * 设置未读消息数量
         */
        easyBars?.setOnTabLoadListener {
            easyBars?.setMsgPointCount(1, 66);//参数一:下标,参数二:未读消息数量
            easyBars?.setHintPoint(3, true);//小红点  参数一:小红点显示的下标，参数二true显示，false不显示
        }
        /**
         * 设置点击消失事件
         */
        easyBars?.onTabClickListener = object :EasyNavigationBar.OnTabClickListener{
            override fun onTabSelectEvent(view: View?, position: Int): Boolean {
                if(position==1){
                    easyBars?.setMsgPointCount(1,0);//点击未读消息消失
                }else if(position==3){
                    easyBars?.setHintPoint(3,false);//点击小红点消失
                }
                return false;
            }

            override fun onTabReSelectEvent(view: View?, position: Int): Boolean {
                return false
            }
        }
        easyBars?.selectTextColor(Color.parseColor("#ED578A"))//选中的文字颜色
        easyBars?.normalTextColor(Color.parseColor("#9D9D9D"))//未选中的文字颜色
        easyBars?.build();//最后一定要记得.build
    }

}
